package com._58city.spark.app.dao;

import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;

import com._58city.spark.app.ext.JsonUtil;


/**
 * @author lihao
 * 根据CPC Display日志，转化的Dto对象
 */
public class CPCDisplayDto implements BaseDto{
	
	public final static char SPLIT = 1;
	public final static int COLUMN_NUM = 28;
	
	
	
	private String cookieId;
	private String userId;
	private String clientIp;
	private String mark;
	private String version;
	private String displayTime;
	private String displayTypeStr; //cateIdStr 维度
	
	private String[] displayTypes; //cateids
	
	private String busiLine; //业务线 
	
	public String getBusiLine() {
		return busiLine;
	}

	public void setBusiLine(String busiLine) {
		this.busiLine = busiLine;
	}

	private String displayRegion;
	private String space;
	private String pageId;
	private String reference;
	private String httpForwarded;
	private String httpUserAgent;
	private String adStr; //广告json串 disp 值
	
	private int adNum; //广告数
	
	private String displayId;
	private String dispLocalId;
	private String disCateId;
	private String param;
	private boolean isExtend;
	private String platform; //platform 维度
	private String abtest;
	private String pid;
	private String imei;
	private String requestUrl;
	private String coordinate;
	private String keyword;
	private String totalcount;
	private String sessionId;
	
	protected long formaterTime; //根据时间间隔格式化的时间点。
	
	
	
	public CPCDisplayDto() {
		super();
	}
	
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public CPCDisplayDto(String... params) {
		super();
		this.cookieId = params[0];
		this.userId = params[1];
		this.clientIp = params[2];
		this.mark = params[3];
		this.version = params[4];
		this.displayTime = params[5];
		this.displayTypeStr = params[6];
		
		this.displayTypes = StringUtils.split(this.displayTypeStr, '|');
		
		this.displayRegion = params[7];
		this.space = params[8];
		this.pageId = params[9];
		this.reference = params[10];
		this.httpForwarded = params[11];
		this.httpUserAgent = params[12];
		this.adStr = params[13];
		
		if(StringUtils.isNotBlank(this.adStr)){
			List<?> ads = JsonUtil.fromJson(this.adStr, List.class);
			if(null != ads){
				for(Object one: ads){
					if(null != one){
						if(one instanceof Map){
							Map<String, Object> map = (Map)one;
							Object a = map.get("a");
							if(null != a){
								List<String> list =(List)a;
								adNum += list.size();
							}
						}
					}
				}
			}
		}
		
		this.displayId = params[14];
		this.dispLocalId = params[15];
		this.disCateId = params[16];
		this.param = params[17];
		this.isExtend = Boolean.valueOf(params[18]);
		this.platform = params[19];
		this.abtest = params[20];
		this.pid = params[21];
		this.imei = params[22];
		this.requestUrl = params[23];
		this.coordinate = params[24];
		this.keyword = params[25];
		this.totalcount = params[26];
		this.sessionId = params[27];
	}

	
	public String[] getDisplayTypes() {
		return displayTypes;
	}

	public void setDisplayTypes(String[] displayTypes) {
		this.displayTypes = displayTypes;
	}

	public String getCookieId() {
		return cookieId;
	}
	public void setCookieId(String cookieId) {
		this.cookieId = cookieId;
	}
	public String getUserId() {
		return userId;
	}
	public void setUserId(String userId) {
		this.userId = userId;
	}
	public String getClientIp() {
		return clientIp;
	}
	public void setClientIp(String clientIp) {
		this.clientIp = clientIp;
	}
	public String getMark() {
		return mark;
	}
	public void setMark(String mark) {
		this.mark = mark;
	}
	public String getVersion() {
		return version;
	}
	public void setVersion(String version) {
		this.version = version;
	}
	public String getDisplayTime() {
		return displayTime;
	}
	public void setDisplayTime(String displayTime) {
		this.displayTime = displayTime;
	}
	
	public String getDisplayRegion() {
		return displayRegion;
	}
	public void setDisplayRegion(String displayRegion) {
		this.displayRegion = displayRegion;
	}
	public String getSpace() {
		return space;
	}
	public void setSpace(String space) {
		this.space = space;
	}
	public String getPageId() {
		return pageId;
	}
	public void setPageId(String pageId) {
		this.pageId = pageId;
	}
	public String getReference() {
		return reference;
	}
	public void setReference(String reference) {
		this.reference = reference;
	}
	public String getHttpForwarded() {
		return httpForwarded;
	}
	public void setHttpForwarded(String httpForwarded) {
		this.httpForwarded = httpForwarded;
	}
	public String getHttpUserAgent() {
		return httpUserAgent;
	}
	public void setHttpUserAgent(String httpUserAgent) {
		this.httpUserAgent = httpUserAgent;
	}
	public String getAdStr() {
		return adStr;
	}
	public void setAdStr(String adStr) {
		this.adStr = adStr;
	}
	public String getDisplayId() {
		return displayId;
	}
	public void setDisplayId(String displayId) {
		this.displayId = displayId;
	}
	public String getDispLocalId() {
		return dispLocalId;
	}
	public void setDispLocalId(String dispLocalId) {
		this.dispLocalId = dispLocalId;
	}
	public String getDisCateId() {
		return disCateId;
	}
	public void setDisCateId(String disCateId) {
		this.disCateId = disCateId;
	}
	public String getParam() {
		return param;
	}
	public void setParam(String param) {
		this.param = param;
	}
	public boolean isExtend() {
		return isExtend;
	}
	public void setExtend(boolean isExtend) {
		this.isExtend = isExtend;
	}
	public String getPlatform() {
		return platform;
	}
	public void setPlatform(String platform) {
		this.platform = platform;
	}
	public String getAbtest() {
		return abtest;
	}
	public void setAbtest(String abtest) {
		this.abtest = abtest;
	}
	public String getPid() {
		return pid;
	}
	public void setPid(String pid) {
		this.pid = pid;
	}
	public String getImei() {
		return imei;
	}
	public void setImei(String imei) {
		this.imei = imei;
	}
	public String getRequestUrl() {
		return requestUrl;
	}
	public void setRequestUrl(String requestUrl) {
		this.requestUrl = requestUrl;
	}
	public String getCoordinate() {
		return coordinate;
	}
	public void setCoordinate(String coordinate) {
		this.coordinate = coordinate;
	}
	public String getKeyword() {
		return keyword;
	}
	public void setKeyword(String keyword) {
		this.keyword = keyword;
	}
	public String getTotalcount() {
		return totalcount;
	}
	public void setTotalcount(String totalcount) {
		this.totalcount = totalcount;
	}
	public String getSessionId() {
		return sessionId;
	}
	public void setSessionId(String sessionId) {
		this.sessionId = sessionId;
	}

	public String getDisplayTypeStr() {
		return displayTypeStr;
	}

	public void setDisplayTypeStr(String displayTypeStr) {
		this.displayTypeStr = displayTypeStr;
	}



	



	@Override
	public String toString() {
		return "CPCDisplayDto [cookieId=" + cookieId + ", userId=" + userId
				+ ", clientIp=" + clientIp + ", mark=" + mark + ", version="
				+ version + ", displayTime=" + displayTime
				+ ", displayTypeStr=" + displayTypeStr + ", busiLine="
				+ busiLine + ", displayRegion=" + displayRegion + ", space="
				+ space + ", pageId=" + pageId + ", reference=" + reference
				+ ", httpForwarded=" + httpForwarded + ", httpUserAgent="
				+ httpUserAgent + ", adStr=" + adStr + ", adNum=" + adNum
				+ ", displayId=" + displayId + ", dispLocalId=" + dispLocalId
				+ ", disCateId=" + disCateId + ", param=" + param
				+ ", isExtend=" + isExtend + ", platform=" + platform
				+ ", abtest=" + abtest + ", pid=" + pid + ", imei=" + imei
				+ ", requestUrl=" + requestUrl + ", coordinate=" + coordinate
				+ ", keyword=" + keyword + ", totalcount=" + totalcount
				+ ", sessionId=" + sessionId + ", formaterTime=" + formaterTime
				+ "]";
	}

	public int getAdNum() {
		return adNum;
	}

	public void setAdNum(int adNum) {
		this.adNum = adNum;
	}

	public long getFormaterTime() {
		return formaterTime;
	}

	public void setFormaterTime(long formaterTime) {
		this.formaterTime = formaterTime;
	}

}
